<template>
	<a-image :width="88" :height="88" ref="img" :src="imgSrc" />
</template>
<script>
import tool from '@/utils/tool'
export default {
	name: 'authImg',
	data() {
		return {
			imgSrc: ''
		}
	},
	props: {
		authSrc: {
			type: String,
			required: false,
			default: ''
		}
	},
	mounted() {
		const fileUrl = import.meta.env.VITE_FILE_URL
		const path = this.authSrc.includes('http') ? this.authSrc : `${fileUrl}/${this.authSrc}`
		let token = tool.data.get('TOKEN')
		// Object.defineProperty(Image.prototype, 'authsrc', {
		// 	writable: true,
		// 	enumerable: true,
		// 	configurable: true
		// })
		let img = this.$refs.img
		let request = new XMLHttpRequest()
		request.responseType = 'blob'
		request.open('get', path, true)
		request.setRequestHeader('Token', token)
		request.onreadystatechange = (e) => {
			if (request.readyState == XMLHttpRequest.DONE && request.status == 200) {
				this.imgSrc = URL.createObjectURL(request.response)
				img.onload = () => {
					URL.revokeObjectURL(this.imgSrc)
				}
			}
		}
		request.send(null)
	},

}
</script>